import 'package:flutter/material.dart';

class SystemQuestionsModel {
  String order;
  String questionType;
  String questionBody;
  String isTrue;
  List questionImg;
  List<Options> options;
  List trueOption;
  List userImage;


  SystemQuestionsModel(
      {this.order,
      this.questionType,
      this.questionBody,
      this.questionImg,
      this.options,
      this.trueOption});

  SystemQuestionsModel.fromJson(Map<String, dynamic> json) {
    userImage = [];

    order = json['order'];
    questionType = json['question_type'];
    isTrue = json['is_true'];
    questionBody = json['question_body'];
    if (json['question_img'] != null) {
      questionImg = new List();
      json['question_img'].forEach((v) {
        questionImg.add(v);
      });
    }
    if (json['options'] != null) {
      options = new List<Options>();
      json['options'].forEach((v) {
        options.add(new Options.fromJson(v));
      });
    }
    trueOption = json['true_option'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['userimage'] = this.userImage;
    data['order'] = this.order;
    data['is_true'] = this.isTrue;
    data['question_type'] = this.questionType;
    data['question_body'] = this.questionBody;
    if (this.questionImg != null) {
      data['question_img'] = this.questionImg.map((v) => v.toJson()).toList();
    }
    if (this.options != null) {
      data['options'] = this.options.map((v) => v.toJson()).toList();
    }
    data['true_option'] = this.trueOption;
    return data;
  }

  String getStringType() {
    if (questionType == "SC") {
      return "[单选]";
    } else if (questionType == "MC") {
      return "[多选]";
    } else if (questionType == "C") {
      return "[问答]";
    }
    return "";
  }

  Color switchColor() {
//    is_true这样吧错：0，对：1，未填：2
    if (isTrue == "0") {
      return Colors.red;
    } else if (isTrue == "1") {
      return Colors.blue;
    } else if (isTrue == "2") {
      return Colors.grey;
    }
    return Colors.grey;
  }
}

class Options {
  String body;
  String order;
  String img;
  bool isCorrect;

  Options({this.body, this.order, this.img, this.isCorrect});

  Options.fromJson(Map<String, dynamic> json) {
    body = json['body'];
    order = json['order'];
    img = json['img'];
    isCorrect = json['is_correct'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['body'] = this.body;
    data['order'] = this.order;
    data['img'] = this.img;
    data['is_correct'] = this.isCorrect;
    return data;
  }


}
